<script>
	import { checkLogin, getToken, getOpenId } from './utils/cookie.js';
	
	export default {
		globalData: {
			isLoggedIn: false,
			token: '',
			openid: ''
		},
		onLaunch: function() {
			console.log('App Launch');
			// 检查登录状态
			this.checkLoginStatus();
		},
		onShow: function() {
			console.log('App Show');
			// 每次显示应用时检查登录状态
			this.checkLoginStatus();
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 检查登录状态
			checkLoginStatus() {
				const isLoggedIn = checkLogin();
				this.globalData.isLoggedIn = isLoggedIn;
				
				if (isLoggedIn) {
					this.globalData.token = getToken();
					this.globalData.openid = getOpenId();
					console.log('用户已登录，token:', this.globalData.token);
				} else {
					console.log('用户未登录');
				}
			}
		}
	}
</script>

<style lang="scss">
	// /*每个页面公共css */
	@import './common/common.css';
	@import '@/static/font/iconfont.css';
</style>
